<!--
	作者：956911785@qq.com
	时间：2019年9月14日17:38:54
	描述：诗词作业检查人员-添加
-->

<template>
	<Modal title="修改" v-model="modal0" width="800px">
		<Form ref="params" :label-width="120" label-position="left">
			<div style="width:100%;min-height:300px;max-height:600px; overflow-y: scroll;">
		      	
				<div style="width:100%;height:40px;line-height: 40px;float:left;text-align: left;">
	        		<div style="width:80%;float:left;">
		      			<FormItem  prop="readid" label="诗词">
				        	<Select v-model="readid" style="width:200px" clearable>
						        <Option v-for="item in poetrys" :value="item.READID" :key="item.PNAME">{{ item.PNAME }}</Option>
						    </Select>
		        		</FormItem>
		      		</div>
		      	</div>
		      	
				<div style="width:100%;float:left;text-align: left;background: #E8E8E8;margin-top:10px;">
					<div style="width:100%;float:left;height:40px;line-height: 40px;">
						<div style="width:80%;float:left;">
							<FormItem label="日期" >
								<DatePicker v-model="riqi" transfer type="datetime" format="yyyy-MM-dd" placeholder="请选择负责检查的日期" style="width:80%"></DatePicker>
							</FormItem>
						</div>
						<div style="width:50px;float:left;">
							<Icon type="md-add-circle" size="20" title="新增" style="cursor: pointer;margin-right:5px;color:#42B983;" @click="addZh()"/>
						</div>
					</div>
					
					<FormItem  label="负责检查的账号">
						<template v-for="(zitem,zindex) in zh">
							<div style="width:38%;float:left;height:40px;line-height: 40px;padding-right:2%;">
								<div style="width:90%;float:left;">
									<Input v-model="zitem.dlzh" placeholder="请填写检查人员的账号" clearable style="width: 100%"></Input>
								</div>
								<div style="width:10%;float:left;">
									<Icon type="md-close-circle" size="20" title="删除" style="cursor: pointer;margin-right:5px;color:#CD3333;" @click="delZh(zindex)"/>
								</div>
							</div>
						</template>
					</FormItem>
				</div>
		      	
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="editsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>

	
	export default {
		name:"tconent",
		props: {
    		editparam:{
    			type:Object,	
    		},
    	},
		data() {
			return {   
                modal0:false,
                num:1,
            	poetrys:[],
            	readid:'',
				riqi:null,
            	zh:[
            		{dlzh:''}
            	]
			} 
		},
		methods: {
			editsave:function(){
				var readid=this.readid;
				if(readid==""){
					this.$Modal.error({
					    title: "提示",
					    content:"请选择诗词！"
					});	
					return;
				}
				var riqidate=this.riqi;
				if(!riqidate){
					this.$Modal.error({
					    title: "提示",
					    content:"请选择负责检查的日期！"
					});	
					return;
				}
				var riqi=this.getNowFormatDate(riqidate);
				var zh=this.zh;
				var weekday=riqidate.getDay();

				var params={
					readid:readid,
					riqi:riqi,
					weekday:weekday,
					zh:JSON.stringify(zh)
				}
				
				this.$http.post("/host/readbook/poetryread/edit_poetryreadscore.html",params)
				.then(datas => {
					if(datas.result){
						this.$Modal.success({
				            title: "提示",
				            content:datas.msg
				       });
				       this.$emit("reload");
				       this.closeModal();
					}else{
						this.$Modal.error({
				            title: "提示",
				            content:datas.msg
				       });	
					}
				});
	        }, 
            closeModal(){
	      	    this.modal0 = false;
	        },
			
			getAllPoetryRead(){	
				this.$http.get("/host/readbook/poetryread/getAllPoetryRead.html")
				.then(result => {	
					this.poetrys=result;
				});
			},
			
			addZh(n){
				var zh=this.zh;
				var zhstr={
					dlzh:''
				}
				zh.push(zhstr);
			},
			
			
			delZh(zindex){
				var zh=this.zh;
				zh.splice(zindex,1);
			},
			
			getNowFormatDate(date) {
				var seperator1 = "-";
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
				return currentdate;
			}
		},
		mounted() {
			//查询诗词
			this.getAllPoetryRead();
		},
		watch:{
			modal0(news,olds){
				if(news){
					this.readid=this.editparam.READID;
					this.riqi=new Date(this.editparam.RIQI);
					var zhs=this.editparam.DLZH;
					var zharr=zhs.split(",");
					var dlarr=[];
					for(var i=0;i<zharr.length;i++){
						var dlstr={
							dlzh:zharr[i]
						}
						dlarr.push(dlstr);
					}
					this.zh=dlarr;
				}else{
					this.readid='';
					this.riqi=null;
	            	this.zh=[
	            		{dlzh:''}
	            	]
				}
			}
		},
		computed: {
		
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



